import util from './utils'
import styles from './style'
import { config as sysconfig } from './config'
import Overlay from 'ol/Overlay'

const overlay = {
    // 绘制overlay
    /**
     * @param {Object} map 地图对象
     * @param {Objetc} element 节点对象
     * @param {Array} lonlats 经纬度
     * @param {Object} attrs 自定义属性
     */
    drawOverlay: (map, element, lonlats, attrs = {}, params = {}) => {
        let param = Object.assign(
            {
                element: element
            },
            params
        )
        console.log('param', param)
        let overlay = new Overlay(param)
        for (let key in attrs) {
            overlay.set(key, attrs[key])
        }
        console.log(overlay, lonlats)
        overlay.setPosition(util.transform(lonlats))

        map.addOverlay(overlay)
        return overlay
    },
    // 移除overlay
    removeOverlay(map, overlay) {
        if (overlay) {
            map.removeOverlay(overlay)
        }
    }
}

export default overlay
